function jcb_monitorname=jcb_get_monitor(names,type,number)

jcb_monitorname='';

if ~(strcmp(type,'index') || strcmp(type,'nearfield'))
    error('jcb:unknownmonitortype','Unknown monitor type ''%s'' passed',type);
end

names=regexp(names,'\n','split');

monitornum=1;
for ii=1:length(names)
    if ~isempty(strfind(names{ii},type))
        if monitornum==number
            jcb_monitorname=names{ii};
            break;
        else
            monitornum=monitornum+1;
        end
    end
end

end